package com.example.module_lzq_haibathree.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;

import com.example.module_lzq_haibathree.R;
import com.example.module_lzq_haibathree.activity.HpSleepMonitorActivity;
import com.example.module_lzq_haibathree.activity.RulerActivity;
import com.example.module_lzq_haibathree.activity.SpiritLevelActivity;
import com.example.module_lzq_haibathree.databinding.FragmentHaibathreeLayoutBinding;
import com.example.module_lzq_haibathree.utils.Time;
import com.fwlst.lib_base.fragment.BaseMvvmFragment;
import com.fwlst.lib_base.model.BaseViewModel;
import com.fwlst.lib_base.utils.AdUtils;


import java.text.SimpleDateFormat;
import java.util.Date;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;

public class Fragment_haibathree extends BaseMvvmFragment<FragmentHaibathreeLayoutBinding, BaseViewModel> {
    private Handler handler;
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            binding.tvHaibathreedates.setText(Time.rg() + Time.yrz() + " " + new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis())));
            handler.postDelayed(this, 1000);
        }
    };

    @Override
    protected int initLayout() {
        return R.layout.fragment_haibathree_layout;
    }

    @Override
    protected int initBR() {
        return 0;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        handler = new Handler(Looper.getMainLooper());
        handler.postDelayed(runnable, 0);
        onclick();

    }

    private void onclick() {
        binding.ivHaibathreeCejuyi.setOnClickListener(v -> {
            AdUtils.INSTANCE.loadCountRewardVideoAd(requireContext(), new Function0<Unit>() {
                @Override
                public Unit invoke() {
                    startActivity(new Intent(requireContext(), RulerActivity.class));
                    return null;
                }
            });

        });
        binding.ivHaibathreeShuipinyi.setOnClickListener(v -> {
            AdUtils.INSTANCE.loadCountRewardVideoAd(requireContext(), new Function0<Unit>() {
                @Override
                public Unit invoke() {
                    startActivity(new Intent(requireContext(), SpiritLevelActivity.class));
                    return null;
                }
            });

        });
        binding.ivHaibathreeFenbeiyi.setOnClickListener(v -> {
            startActivity(new Intent(requireContext(), HpSleepMonitorActivity.class));
        });
        binding.ivHaibathreeChizi.setOnClickListener(v -> {
            AdUtils.INSTANCE.checkFunction(requireContext(), new Function0<Unit>() {
                @Override
                public Unit invoke() {

                    return null;
                }
            });

        });
        binding.ivHaibathreeShuiyinxiangji.setOnClickListener(v -> {

        });
        binding.ivHaibathreeCegao.setOnClickListener(v -> {
            // 组合权限
//            List<String> list = new ArrayList<>();
//            list.add(PermissionCase.PER_CAMERA);
//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//                list.add(PermissionCase.PER_READ_IMAGES);
//            } else {
//                list.add(PermissionCase.PER_STORAGE_WRITE);
//                list.add(PermissionCase.PER_STORAGE_READ);
//            }
//            AllowPermissionUseCase.requestWithPreviewDialogMulti(this, list, "组合", "请开启权限", () -> {
//                AdUtils.INSTANCE.loadCountRewardVideoAd(requireContext(), new Function0<Unit>() {
//                    @Override
//                    public Unit invoke() {
//                        CameraActivity.Companion.startMeasureHeight(requireContext());
//                        return null;
//                    }
//                });
//
//                return null;
//            });
        }
        );

    }
}
